package com.ulinkle.ulinkle_muhf.base;

import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;

import com.speedata.libuhf.UHFManager;
import com.speedata.libuhf.interfaces.OnSpdBanMsgListener;
import com.ulinkle.ulinkle_muhf.R;
import com.ulinkle.ulinkle_muhf.uhf.UHFUtil;
import com.ulinkle.ulinkle_muhf.weight.floatball.FloatWarnManager;
import com.ulinkle.ulinkle_muhf.weight.floatwindow.FloatWindow;

/**
 * @Description: java类作用描述
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class BaseActivity extends AppCompatActivity {
    public static boolean isLowPower = false;
    public static boolean isHighTemp = false;
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //全屏显示  Full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //强制为竖屏     Force to vertical screen mode
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//        setBuilder();
        Log.d("zzc","BaseActivity onCreate");
    }

     private void setBuilder() {
        UHFManager uhfManager = new UHFManager();
        uhfManager.setOnBanMsgListener(new OnSpdBanMsgListener() {
            @Override
            public void getBanMsg(String var1) {
                Log.e("zzc:UHFService", "====监听报警====");
                if (var1.contains("Low")) {
                    isLowPower = true;
                    var1 = BaseActivity.this.getResources().getString(R.string.low_power);
                } else if (var1.contains("High")) {
                    isHighTemp = true;
                    var1 = BaseActivity.this.getResources().getString(R.string.high_temp);
                }
                final String finalVar = var1;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        FloatWarnManager.getInstance(getApplicationContext(), finalVar);
                        FloatWarnManager floatWarnManager = FloatWarnManager.getFloatWarnManager();
                        if (floatWarnManager != null) {
                            FloatWindow.get("FloatWarnTag").show();
                        }
                    }
                });
            }
        });
    }
     @Override
    protected void onResume() {
        super.onResume();
         /**
          * 进入界面时关闭下盘存
          */
        if (UHFUtil.getInstance().getIuhfService() != null) {
            UHFUtil.getInstance().getIuhfService().inventoryStop();
            UHFUtil.isStart = false;
        }
    }

    @Override
    protected void onDestroy() {
        Log.d("zzc","BaseActivity onDestroy");
        super.onDestroy();
    }


}
